﻿using System;
using System.Collections.Generic;
using Xunit;

namespace UniSender.Test
{

    public class TestClient
    {
        [Fact]
        public void TestExceptionOnCalling()
        {
            var client = new ClientStub()
            {
                StubRequest = (m, a) => { throw new Exception(); }
            };
            Assert.Throws<UniSenderTransportException>(() => {
                client.Call<object>("action");
            });
            Assert.DoesNotThrow(() => {
                client.TryCall<object>("action");
            });
        }

        [Fact]
        public void TestSilentMode()
        {
            var client = new ClientStub()
            {
                StubRequest = (m, a) => { throw new Exception(); }
            };

            client.MuteExceptions = true;
            Assert.DoesNotThrow(() => {
                client.Apply<object>("action");
            });

            client.MuteExceptions = false;
            Assert.Throws<UniSenderTransportException>(() =>
            {
                client.Apply<object>("action");
            });
        }
    }
}
